package com.binary.markdownrecord.config.template;

import com.binary.markdownrecord.util.PageAndOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//import ${package}.service.EvTemplateService;
//import ${model}.EvTemplate;

@RestController
@RequestMapping("/rest/common/evTemplate/v1")
@Api(value = "/rest/common/evTemplate/v1", tags = {"EvTemplate"})
public class EvTemplateController {
    @Autowired
    private EvTemplateService evTemplateService;


    @ApiOperation(notes = "/", value = "保存EvTemplate")
    @PostMapping("/")
    public EvTemplate save(@RequestBody EvTemplate obj) {
        return evTemplateService.save(obj);
    }

    @ApiOperation(notes = "/{id}", value = "根据ID删除EvTemplate")
    @DeleteMapping("/{id}")
    public void delete(@PathVariable String id) {
        evTemplateService.delete(id);
    }

    @ApiOperation(notes = "/{id}", value = "根据ID获取EvTemplate")
    @GetMapping("/{id}")
    public EvTemplate getById(@PathVariable String id) {
        return evTemplateService.getById(id);
    }

    @ApiOperation(notes = "/list", value = "列出所有EvTemplate")
    @GetMapping("/list")
    public List<EvTemplate> listAll() {
        return evTemplateService.listAll();
    }

    @ApiOperation(notes = "/page", value = "分页查询EvTemplate")
    @GetMapping("/page")
    public Page<EvTemplate> page(Integer page, Integer pageSize) {
        return evTemplateService.page(PageRequest.of(page, pageSize));
    }

    @ApiOperation(notes = "/pageAndSort", value = "分页查询EvTemplate排序")
    @PostMapping("/pageAndSort")
    public Page<EvTemplate> pageAndSort(@RequestBody PageAndOrder pageAndOrder) {
        Integer page = pageAndOrder.getPage();
        Integer pageSize = pageAndOrder.getPageSize();
        return evTemplateService.page(PageRequest.of(page, pageSize, Sort.by(pageAndOrder.offerSortOrder())));
    }
}
